import { Form } from "./Form.js";

export class Shape {
    #color: string;
    #forms: Form[];

    constructor(colorIndex: number, forms: Form[]) {
        this.#color = `c${colorIndex}`;
        this.#forms = forms;
    }

    get color(): string {
        return this.#color;
    }

    getForm(index: number): Form {
        const formsCount = this.#forms.length;
        return this.#forms[index % formsCount];
    }

    get formsCount(): number {
        return this.#forms.length;
    }
}

// 预先定义各方块的形式和四种方向的形态
export const SHAPES = [
    // 正方形
    [
        [[0, 0], [0, 1], [1, 0], [1, 1]]
    ],
    // |
    [
        [[0, 0], [0, 1], [0, 2], [0, 3]],
        [[0, 0], [1, 0], [2, 0], [3, 0]]
    ],
    // L
    [
        [[0, 0], [0, 1], [0, 2], [1, 2]],
        [[0, 0], [1, 0], [2, 0], [0, 1]],
        [[0, 0], [1, 0], [1, 1], [1, 2]],
        [[2, 0], [0, 1], [1, 1], [2, 1]]
    ],
    // 反 L
    [
        [[1, 0], [1, 1], [0, 2], [1, 2]],
        [[0, 0], [0, 1], [1, 1], [2, 1]],
        [[0, 0], [1, 0], [0, 1], [0, 2]],
        [[0, 0], [1, 0], [2, 0], [2, 1]]
    ],
    // Z
    [
        [[0, 0], [1, 0], [1, 1], [2, 1]],
        [[1, 0], [0, 1], [1, 1], [0, 2]]
    ],
    // 反 Z
    [
        [[1, 0], [2, 0], [0, 1], [1, 1]],
        [[0, 0], [0, 1], [1, 1], [1, 2]]
    ],
    // T
    [
        [[0, 0], [1, 0], [2, 0], [1, 1]],
        [[1, 0], [0, 1], [1, 1], [1, 2]],
        [[1, 0], [0, 1], [1, 1], [2, 1]],
        [[0, 0], [0, 1], [1, 1], [0, 2]]
    ]
].map((formData, i) => {
    const forms = formData.map(points => new Form(points));
    return new Shape(i, forms);
});
